package com.kgc.novel.controller;

import com.kgc.novel.common.Res;
import com.kgc.novel.domain.entity.BookClassify;
import com.kgc.novel.domain.param.BookClassifyParam;
import com.kgc.novel.service.book.BookClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mac
 */
@RestController
@RequestMapping("/book/classify")
@Slf4j
@Api(tags = "小说分类管理")
@CrossOrigin(originPatterns = "*")
public class BookClassifyController {

    @Resource
    private BookClassifyService bookClassifyService;

    @PostMapping("/list")
    @ApiOperation("查询全部信息")
    public Res selectList(@RequestBody(required = false) BookClassifyParam bookClassifyParam){
        return bookClassifyService.selectAll(bookClassifyParam);
    }

    @PostMapping("/listNoPage")
    @ApiOperation("查询全部信息，不分页")
    public Res selectListNoPage(){
        return bookClassifyService.selectAllNoPage();
    }

    @GetMapping("/select/{id}")
    @ApiOperation("查询单个信息")
    public Res selectAuthor(@PathVariable("id") String id){
        return bookClassifyService.getSingle(id);
    }

    @PostMapping("/addOrUpdate")
    @ApiOperation("新增或者修改信息")
    public Res addAuthor(@RequestBody(required = true) BookClassify bookClassify){
        if (bookClassify.getId() == null){
            return bookClassifyService.addSingle(bookClassify);
        }
        return bookClassifyService.updateSingle(bookClassify);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除单个信息")
    public Res deleteAuthor(@PathVariable("id") String id){
        return bookClassifyService.deleteSingle(id);
    }

    @DeleteMapping("/deleteAll/{ids}")
    @ApiOperation("批量删除信息")
    public Res deleteAllAuthor(@PathVariable("ids") List<String> ids){
        return bookClassifyService.deleteAll(ids);
    }

}
